package com.zbkj.service.service.mszs;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.zbkj.common.model.mszs.MszsQimoReceivekey;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.mszs.MszsQimoReceivekeyRequest;
import com.zbkj.common.request.mszs.MszsQimoReceivekeySelectRequest;
import com.zbkj.common.response.mszs.MszsQimoReceivekeyResponse;
import com.zbkj.service.dao.mszs.MszsQimoReceivekeyDao;
import com.zbkj.service.service.mszs.MszsQimoReceivekeyService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @description 民宿助手-接受七陌按键信息
 * @author zhengkai.blog.csdn.net
 * @date 2023-11-16
 */
@Service
public class MszsQimoReceivekeyServiceImpl  extends ServiceImpl<MszsQimoReceivekeyDao, MszsQimoReceivekey> implements MszsQimoReceivekeyService {

    @Autowired
    private MszsQimoReceivekeyDao qimoReceivekeyDao;

    @Override
    public boolean insert(MszsQimoReceivekeyRequest request) {
        MszsQimoReceivekey receivekey=new MszsQimoReceivekey();
        BeanUtils.copyProperties(request, receivekey);
        int tt = qimoReceivekeyDao.insert(receivekey);
        return tt > 0;
    }

    @Override
    public boolean update(MszsQimoReceivekeyRequest request) {

        MszsQimoReceivekey receivekey=new MszsQimoReceivekey();
        BeanUtils.copyProperties(request, receivekey);
        int tt = qimoReceivekeyDao.updateById(receivekey);
        return tt > 0;
    }

    @Override
    public boolean delete(Integer id) {
        MszsQimoReceivekey receivekey=new MszsQimoReceivekey();
        receivekey.setId(id);
        receivekey.setIsDel(1);
        int tt = qimoReceivekeyDao.updateById(receivekey);
        return tt > 0;
    }

    @Override
    public MszsQimoReceivekeyResponse load(Integer id) {
        MszsQimoReceivekey room = qimoReceivekeyDao.selectById(id);

        MszsQimoReceivekeyResponse roomResponse=new MszsQimoReceivekeyResponse();
        BeanUtils.copyProperties(room,roomResponse);
        return roomResponse;
    }

    @Override
    public List<MszsQimoReceivekey> pageList(MszsQimoReceivekeySelectRequest request, PageParamRequest pageParamRequest) {
        PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        LambdaQueryWrapper<MszsQimoReceivekey> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(request.getKeyInfo())){
            lambdaQueryWrapper.eq(MszsQimoReceivekey::getKeyInfo,request.getKeyInfo());
        }
        if (StringUtils.isNotEmpty(request.getSmsTemplateId())){
            lambdaQueryWrapper.eq(MszsQimoReceivekey::getSmsTemplateId,request.getSmsTemplateId());
        }
        lambdaQueryWrapper.orderByDesc(MszsQimoReceivekey::getCreateTime);

        List<MszsQimoReceivekey> hotelList = qimoReceivekeyDao.selectList(lambdaQueryWrapper);
        if (CollUtil.isEmpty(hotelList)) {
            return CollUtil.newArrayList();
        }
        return hotelList;
    }

}
